#include"Table.h"
#include <iostream>
Table::Table(int numberOfPlayers)
{
  /* Make sure the number of players is correct. */
  assert(numberOfPlayers > 1);
  assert(numberOfPlayers < 5);
  /* Create players. */
  for(int i = 0; i < numberOfPlayers; i++)
    players.push_back(Player());
  /* Build deck to distribute. */
  Deck allCards;
  int nextID = 0;
  /* Jokers. */
  int jokerCount = 2;
  /* Extra 2 jokers if you have 2 decks. */
  if(numberOfPlayers > 2) jokerCount += 2;
  for(int i = 0; i < jokerCount; ++i)
    allCards.add(new Card(clubs, joker, nextID++));
  for(Rank r = ace; r <= king; r=(Rank)((int)r+1))
    for(Suit s = diamonds; s <= clubs; s=(Suit)((int)s+1))
    {
      allCards.add(new Card(s, r, nextID++));
      /* Extra card if you have 2 decks. */
      if(numberOfPlayers > 2)
        allCards.add(new Card(s, r, nextID++));
    }
  allCards.shuffle();
  /* Calculate number of cards per player. */
  int cardsPerPlayer = 54;
  if(numberOfPlayers > 2)
    cardsPerPlayer *= 2;
  cardsPerPlayer /= numberOfPlayers;
  /* Spit the cards between the players. */
  for(int i = 0; i < numberOfPlayers; ++i)
    allCards.transfer(cardsPerPlayer, players.at(i).getArmy());

  /* Draw cards from each player's deck into their hands until full*/
  for(int i = 0; i < numberOfPlayers; ++i)
    players.at(i).refillHand();
  /* Default values. */
  warTime = false;
  soloMover = &players.at(rand()%numberOfPlayers);
}
